package {{packageName}}.server.router.impl.biz

import com.firefly.annotation.Component
import com.firefly.annotation.Inject
import com.firefly.codec.http2.model.HttpMethod
import com.firefly.kotlin.ext.http.HttpServer
import {{packageName}}.api.model.vo.Response
import {{packageName}}.api.service.ProjectService
import {{packageName}}.server.router.RouterInstaller

/**
 * @author Pengtao Qiu
 */
@Component("projectRouter")
class ProjectRouter : RouterInstaller {

    @Inject
    private lateinit var server: HttpServer

    @Inject
    private lateinit var projectService: ProjectService

    override fun install() = server.addRouters {

        router {
            httpMethod = HttpMethod.GET
            path = "/project/:id"

            asyncCompleteHandler {
                val id = getPathParameter("id").toLong()
                writeJson(Response(projectService.get(id)))
            }
        }
    }
}